/*
 * Sales Data Controller Project.
 * Copyright (C) 2011 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see 
 * http://www.gnu.org/licenses/.
 */

package be.fedict.sdc.vsc;

import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class VATSigningCard {

	public static final byte[] VSC_AID = new byte[] { (byte) 0xA0, 0x00, 0x00,
			0x01, 0x77, 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };

	private static final Log LOG = LogFactory.getLog(VATSigningCard.class);

	protected final CardChannel cardChannel;

	public VATSigningCard(CardChannel cardChannel) throws CardException {
		this.cardChannel = cardChannel;
		CommandAPDU selectApplicationApdu = new CommandAPDU(0x00, 0xA4, 0x04,
				0x0C, VSC_AID);
		ResponseAPDU responseApdu = this.cardChannel
				.transmit(selectApplicationApdu);
		int statusWord = responseApdu.getSW();
		if (0x9000 != statusWord) {
			throw new CardException("not a VAT Signing Card ");
		}
		LOG.debug("VAT signing card detected");
	}
}
